package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.NumbersIntroduce;
import com.yunang.officialweb.service.NumberService;
import com.yunang.officialweb.service.TotalService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author 唐帅
 */
@RestController
@RequestMapping("/OfficialWebsite")
public class NumbersController {
    @Autowired
    private NumberService numberService;

    @Autowired
    private TotalService totalService;

    @ApiOperation("查询Home页的信息")
    @RequestMapping(value = "/getTotalPageOfHome", method = RequestMethod.GET)
    public R getNumbersIntroduce(){
        return R.ok(numberService.getExcellentNumber());
    }

    @ApiOperation("更新NumbersIntroduce")
    @RequestMapping(value = "/updateNumbersIntroduce", method = RequestMethod.PUT)
    public R updateNumbersIntroduce(@RequestParam int id,
                        @RequestParam(required = false) MultipartFile image,
                        @RequestParam(required = false) String numberName,
                        @RequestParam(required = false) String department){
        NumbersIntroduce numbersIntroduce = new NumbersIntroduce();
        numbersIntroduce.setId(id);
        numbersIntroduce.setImage(totalService.savePic(image, "D://YunAng-web//numbInt"));
        numbersIntroduce.setNumberName(numberName);
        numbersIntroduce.setDepartment(department);
        return R.ok(numberService.updateNumberIntroduce(numbersIntroduce));
    }

}
